package com.ruoyi.web.controller.decision;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.decision.domain.Menu;
import com.ruoyi.decision.domain.StrategyClassification;
import com.ruoyi.decision.service.IStrategyClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优化策略分类Controller
 * 
 * @author zbw
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/decision/strategyclassification")
public class StrategyClassificationController extends BaseController
{
    @Autowired
    private IStrategyClassificationService strategyClassificationService;

    /**
     * 查询优化策略分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:slist')")
    @GetMapping("/slist")
    public TableDataInfo slist()
    {
        List<Menu> menus = strategyClassificationService.treemenu();
        return getDataTable(menus);
    }

    /**
     * 查询优化策略分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:list')")
    @GetMapping("/list")
    public TableDataInfo list(StrategyClassification strategyClassification)
    {
        startPage();
        List<StrategyClassification> list = strategyClassificationService.selectStrategyClassificationList(strategyClassification);
        return getDataTable(list);
    }

    /**
     * 导出优化策略分类列表
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:export')")
    @Log(title = "优化策略分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StrategyClassification strategyClassification)
    {
        List<StrategyClassification> list = strategyClassificationService.selectStrategyClassificationList(strategyClassification);
        ExcelUtil<StrategyClassification> util = new ExcelUtil<StrategyClassification>(StrategyClassification.class);
        util.exportExcel(response, list, "优化策略分类数据");
    }

    /**
     * 获取优化策略分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:query')")
    @GetMapping(value = "/{strategyTypeId}")
    public AjaxResult getInfo(@PathVariable("strategyTypeId") String strategyTypeId)
    {
        return AjaxResult.success(strategyClassificationService.selectStrategyClassificationByStrategyTypeId(strategyTypeId));
    }

    /**
     * 新增优化策略分类
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:add')")
    @Log(title = "优化策略分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StrategyClassification strategyClassification)
    {
        return toAjax(strategyClassificationService.insertStrategyClassification(strategyClassification));
    }

    /**
     * 修改优化策略分类
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:edit')")
    @Log(title = "优化策略分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StrategyClassification strategyClassification)
    {
        return toAjax(strategyClassificationService.updateStrategyClassification(strategyClassification));
    }

    /**
     * 删除优化策略分类
     */
    @PreAuthorize("@ss.hasPermi('decision:strategyclassification:remove')")
    @Log(title = "优化策略分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{strategyTypeIds}")
    public AjaxResult remove(@PathVariable String[] strategyTypeIds)
    {
        return toAjax(strategyClassificationService.deleteStrategyClassificationByStrategyTypeIds(strategyTypeIds));
    }
}
